package com.wy.poties.vo;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class Page<T> implements Serializable {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * 当前页
     */
    public static final String PAGE_NUMBER = "pageNum";

    /**
     * 每页大小
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 总页数
     */
    public static final String TOTAL_SIZE = "totalPageNum";

    public static final String CURRENT_PAGE = "pageNextNum";

    public static final int DEFAULT_SIZE = 10;

    public static final String PAGE_LIST = "page_list";

    private Integer pageNum = 1;

    private Integer pageSize = 10;

    private Integer totalPageNum;

    private Integer totalRows;

    private Integer pageCurrentNum = 1;

    private List<T> pageList;


    public Page() {
        super();
    }


    public Page(Integer pageNum, Integer pageSize) {
        super();
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }


    public static <T> Page<T> getConvertPage(Integer pageNum, Integer pageSize, PageInfo<T> pageInfo) {
        Page<T> page = new Page<>();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        page.setPageList(pageInfo.getList());
        long total = pageInfo.getTotal();
        page.setTotalRows((int) total);
        //总页数
        Integer totalPageNum = pageInfo.getPages();
        page.setTotalPageNum(totalPageNum);
        //返回后当前页
        page.setPageCurrentNum(page.getPageNum() + 1);

        return page;
    }


}
